package com.ywwxhz.plugins.battery.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.ywwxhz.Util.Config;
import com.ywwxhz.plugins.battery.BatteryModel;
import com.ywwxhz.service.CoreService;

public class BatteryReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent updateIntent = new Intent(context, CoreService.class);
        updateIntent.putExtra(Config.SERVICE_PARAM, BatteryModel.MODEL);
        updateIntent.putExtra(BatteryModel.PARAM, BatteryModel.INFO_UPDATE);
        if (intent.getAction() == Intent.ACTION_POWER_CONNECTED
                || intent.getAction() == Intent.ACTION_POWER_DISCONNECTED) {
            updateIntent.putExtra("charge", 1);
        }
        context.startService(updateIntent);
    }
}
